export function faceContent(content) {
	var faceAlt = ["[微笑]", "[撇嘴]", "[色]", "[发呆]", "[得意]", "[流泪]", "[害羞]", "[闭嘴]", "[睡]", "[大哭]", "[尴尬]", "[发怒]", "[调皮]", "[呲牙]", "[惊讶]", "[难过]", "[酷]", "[冷汗]", "[抓狂]", "[吐]", "[偷笑]", "[可爱]", "[白眼]", "[傲慢]", "[饥饿]", "[困]", "[惊恐]", "[流汗]", "[憨笑]", "[大兵]", "[奋斗]", "[咒骂]", "[疑问]", "[嘘]", "[晕]", "[折磨]", "[衰]", "[骷髅]", "[敲打]", "[再见]", "[擦汗]", "[抠鼻]", "[鼓掌]", "[糗大了]", "[坏笑]", "[左哼哼]", "[右哼哼]", "[哈欠]", "[鄙视]", "[委屈]", "[快哭了]", "[阴险]", "[亲亲]", "[吓]", "[可怜]", "[菜刀]", "[西瓜]", "[啤酒]", "[篮球]", "[乒乓]", "[咖啡]", "[饭]", "[猪头]", "[玫瑰]", "[凋谢]", "[示爱]", "[爱心]", "[心碎]", "[蛋糕]", "[闪电]", "[炸弹]", "[刀]", "[握手]", "[胜利]", "[便便]", "[NO]", "[OK]", "[抱拳]", "[弱]", "[强]"];
	//支持的html标签
	var html = function(end) {
		return new RegExp('\\n*\\[' + (end || '') + '(pre|div|p|table|thead|th|tbody|tr|td|ul|li|ol|li|dl|dt|dd|h2|h3|h4|h5)([\\s\\S]*?)\\]\\n*', 'g');
	};
	content = (content || '').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&amp;')
		.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#39;').replace(/"/g, '&quot;') //XSS
		.replace(/@(\S+)(\s+?|$)/g, '@<a href="javascript:;">$1</a>$2') //转义@
		.replace(/\s{2}/g, '&nbsp') //转义空格
		.replace(/\[([^\s\[\]]+?)\]/g, function(face) { //转义表情
			var alt = face.replace(/^face/g, '');
			var num = $.inArray(alt, faceAlt);
			//匹配不到则返回
			if(num == -1) {
				return content
			}
			return '/b' + num;
		}).replace(/\&\#47\;b\d{1,2}/g, function(t) {
			var num = t.replace(/\&\#47\;b/g, '');
			return faceAlt[num];
		})
	return content;
}
export function customLazyLoad(selector) {
	var lazyloadImages;
	if("IntersectionObserver" in window) {
		lazyloadImages = document.querySelectorAll(selector);
		var imageObserver = new IntersectionObserver(function(entries, observer) {
			entries.forEach(function(entry) {
				if(entry.isIntersecting) {
					var image = entry.target;
					image.src = image.dataset.src;
					image.onload = function(){
						this.classList.remove("lazy");
					}
					imageObserver.unobserve(image);
				}
			});
			if(lazyloadImages.length === 0){
				imageObserver.disconnect();
			}
		});

		lazyloadImages.forEach(function(image) {
			imageObserver.observe(image);
		});
	} else {
		var lazyloadThrottleTimeout;
		lazyloadImages = document.querySelectorAll(selector);

		function lazyload() {
			if(lazyloadThrottleTimeout) {
				clearTimeout(lazyloadThrottleTimeout);
			}
			lazyloadThrottleTimeout = setTimeout(function() {
				var scrollTop = window.pageYOffset;
				[...lazyloadImages].forEach(function(img) {
					if((img.getBoundingClientRect().top + scrollTop) < (window.innerHeight + scrollTop)) {
						img.onload = function(){
							this.classList.remove("lazy");
						}
						img.src = img.dataset.src;
					}
				});
				if(lazyloadImages.length === 0) {
					document.removeEventListener("scroll", lazyload);
					window.removeEventListener("resize", lazyload);
					window.removeEventListener("orientationChange", lazyload);
				}
			}, 20);
		}

		document.addEventListener("scroll", lazyload);
		window.addEventListener("resize", lazyload);
		window.addEventListener("orientationChange", lazyload);
	}
}